package com.lemon.ai.socket.packets.spiritgame.model.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

import com.lemon.ai.socket.packets.spiritgame.model.db.MetaData;
import com.lemon.ai.socket.packets.spiritgame.model.dto.Table;
import com.lemon.ai.socket.packets.spiritgame.model.generator.DaoIfcGenerator;

public class FileUtils {
	
	private Properties prop = new Properties();
	private FileWriter out;
	
	public FileUtils() {
		try {
			this.prop.load(new FileInputStream(new File(
					System.getProperty("user.dir") + "\\mysql.properties")));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void write(String file, String content) {
		try {
			File f = new File(file);
			if(!f.exists())	{
				File path = new File(file.substring(0, file.lastIndexOf("\\")));
				path.mkdirs();
				f.createNewFile();
			}
			out = new FileWriter(f);
			out.write(content);
//			System.out.println(file);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		DaoIfcGenerator g = new DaoIfcGenerator();
		FileUtils fu = new FileUtils();
		MetaData meta = MetaData.getInstance();
		Table table = meta.getTables().get(0);
		fu.write(g.generateFileName(table), g.generate(table));
	}

}
